require("../../../utils/function.js");

var e = getApp(), t = require("../../../api.js");

Page({
    data: {
        money: 0
    },
    changeInputData: function(e) {
        var t = this, a = e.currentTarget.dataset.name, n = e.detail.value;
        "money" == a && t.setData({
            money: n
        });
    },
    onLoad: function(e) {},
    sendRequest: function() {
        var a = this;
        if (!a.data.money) return wx.showToast({
            title: "请输入金额",
            icon: "none"
        }), !1;
        var n = a.data.money;
        e.request({
            url: t.user.recharge,
            method: "post",
            data: {
                price: n
            },
            success: function(e) {
                if (console.log(e), 1 == e.code) {
                    var t = e.data;
                    wx.requestPayment({
                        timeStamp: t.timeStamp,
                        nonceStr: t.nonceStr,
                        package: t.package,
                        signType: t.signType,
                        paySign: t.paySign,
                        success: function(e) {
                            wx.showToast({
                                title: "充值成功",
                                duration: 1e3,
                                success: function() {
                                    setTimeout(function() {
                                        wx.navigateBack({
                                            delta: 1
                                        });
                                    }, 1e3);
                                }
                            });
                        },
                        fail: function() {
                            wx.showToast({
                                title: "支付失败",
                                icon: "none",
                                mask: !0
                            });
                        }
                    });
                } else wx.showToast({
                    title: "支付失败",
                    icon: "none",
                    mask: !0
                });
            }
        });
    }
});